using System;
using System.Data;
using System.Collections.Generic;

namespace shfa.snomtastic.data.business
{
    public partial class SiteNavController
    {

        private List<SiteNavInfo> FillCollection(IDataReader dr)
		{
			return FillCollection( dr, true);
		}

        private List<SiteNavInfo> FillCollection(IDataReader dr, bool ManageDataReader)
		{
            List<SiteNavInfo> objToFill = new List<SiteNavInfo>();
			while( dr.Read() )
			{
				objToFill.Add( FillObject( dr, false ) );
			}

			if( ManageDataReader )
                if( dr != null )
                    dr.Close();
			
			return objToFill;
		}

        private SiteNavInfo FillObject(IDataReader dr)
		{
			return FillObject(dr, true);
		}

        private SiteNavInfo FillObject(IDataReader dr, bool ManageDataReader)
        {
			if( dr == null ) return null;

			if( ManageDataReader )
				if( !dr.Read() ) return null;

			SiteNavInfo obj = new SiteNavInfo();

			int Count = dr.FieldCount;
            for (int i = 0; i<Count; i++) {
                switch(dr.GetName(i))
                { 
					case "SiteNavId":
                        obj.SiteNavId = dr.GetGuid(i);
						break;
					case "Name":
						obj.Name = (!dr.IsDBNull(i)) ? dr.GetString(i) : string.Empty;
						break;
                    case "ImageUrl":
                        obj.ImageUrl = (!dr.IsDBNull(i)) ? dr.GetString(i) : string.Empty;
						break;
                    case "ControlUrl":
                        obj.ControlUrl = (!dr.IsDBNull(i)) ? dr.GetString(i) : string.Empty;
                        break;
                    case "ParentId":
                        obj.ParentId = (!dr.IsDBNull(i)) ? dr.GetGuid(i) : Guid.Empty;
                        break;
					case "IsDefault":
                        obj.SortOrder = dr.GetInt32(i);
						break;
				}
			}

			if( ManageDataReader )
                if( dr != null )
                    dr.Close();

			return obj;
		}
    }
}
